package com.my.lab.receiver;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BluetoothReceiver extends BroadcastReceiver {
    
    private static final String TAG = BluetoothReceiver.class.getName();

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,0);
            int preState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE , 0);
            Log.d(TAG, "bluetooth new state:"+newState+",prestate:"+preState);
        } else if(BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG , "found device>>name:"+device.getName()+",address:"+device.getAddress());
        } else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            Log.d(TAG, "find finished...");
        }

    }
}
